/*
 * User: user
 * Date: 16/02/2008
 * Time: 20:22:54
 */
package org.conann.instrument;

import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;
import java.security.ProtectionDomain;

@Deprecated
public class AOPTransformer implements ClassFileTransformer {

    public boolean isNonAdvisableClassName(String classname) {
        return (classname.startsWith("org.jboss.aop") ||
                classname.endsWith("$aop") ||
                classname.startsWith("javassist") ||
                classname.startsWith("org.jboss.util.") ||
                classname.startsWith("gnu.trove.") ||
                classname.startsWith("EDU.oswego.cs.dl.util.concurrent.") ||
                // System classes
                classname.startsWith("org.apache.crimson") ||
                classname.startsWith("org.apache.xalan") ||
                classname.startsWith("org.apache.xml") ||
                classname.startsWith("org.apache.xpath") ||
                classname.startsWith("org.ietf.") ||
                classname.startsWith("org.omg.") ||
                classname.startsWith("org.w3c.") ||
                classname.startsWith("org.xml.sax.") ||
                classname.startsWith("sunw.") ||
                classname.startsWith("sun.") ||
                classname.startsWith("java.") ||
                classname.startsWith("javax.") ||
                classname.startsWith("com.sun."));
    }

    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
        if (isNonAdvisableClassName(className)) {
            return null;
        }
        return aspectTransform(className, loader, classBeingRedefined, protectionDomain, classfileBuffer);
    }

    private byte[] aspectTransform(String className, ClassLoader loader, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) {
        try {
            className = className.replace('/', '.');
//            return AspectManager.instance().transform(loader, className, classBeingRedefined, protectionDomain, classfileBuffer);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return null;
    }
}